#include "main.h"
#include "lattice.h"
#include <fstream>
#include <sstream>

void lattice(char* filename, int& ns, vector<int>& ll, vector<int>& lu, vector<vec3>& R)
{							
    string s;
    int ntemp, kb0;
    vec3 rtemp;
    istringstream iss;
    
    ifstream in(filename, ifstream::in);     // open fort.15
    
    if(!in){				     // ensure existence of file
	    cout<<"error: file "<<filename<<" does not exist\n";
	    exit(-1);
    }

    ll.clear();	                             // clear the vectors
    lu.clear();
    R.clear();
    getline(in, s);
    iss.str(s);
    iss>>XSIZE>>YSIZE>>ZSIZE;	             // read box size
    getline(in, s);			     // read ll
    for (iss.clear(),iss.str(s); iss>>ntemp; ll.push_back(ntemp));
    
    getline(in, s);	                     // read lu	
    for (iss.clear(),iss.str(s); iss>>ntemp; lu.push_back(ntemp));
    
    getline(in, s);								
    iss.clear();
    iss.str(s);
    iss>>kb0;                               // read k0
    
    ns = ll.size();                         // get ns

    R.push_back(VO);                        // set up the [0] index
    for (; getline(in, s);){                // read initial positions
    iss.clear();
    iss.str(s);
	    iss>>rtemp.x>>rtemp.y>>rtemp.z>>rtemp.ic;
	    R.push_back(rtemp);
    }
    
    in.close();				    // close fort.15
}



